import requests

import warnings

warnings.filterwarnings('ignore')

def send_file(file_type, event_id, req_id, cc_id, ist_id, obs_time, file_path):
    # url = 'http://localhost:8080/dataManagement_war_exploded/uploadfile'
    url = 'https://svom-gwacn.cn/dataupload/uploadfile'
    data = {'file-type':file_type,
            'event-id':event_id,
            'req-id':req_id,
            'cc-id': cc_id,
            'ist-id' : ist_id,
            'obs-time' : obs_time,}
    files = {'image': open(file_path, 'rb')}
    res = requests.post(url, data=data, files=files)
    # res = requests.post(url, files=files)
    print(res.text)
    print(res.content)


if __name__ == '__main__':
    #image_path = '/Users/gwac/john/data/flat/flat_I_220103_00001.fit'
    #send_file('fits', '1', '2','3', '4', '2021-01-01 10:10:00', image_path)
    #file_type = xargs
    file_type = float(sys.argv[1])
    event_id = float(sys.argv[2])
    req_id = float(sys.argv[3])
    cc_id = float(sys.argv[4])
    ist_id = float(sys.argv[5])
    obs_time = str(sys.argv[6])
    #2021-01-01T10:10:00
    image_path = str(sys.argv[7])
    send_file(file_type, event_id, req_id, cc_id, ist_id, obs_time, image_path )
    #send_file('file_type', 'event_id', 'req_id', 'cc_id', 'ist_id', '2021-01-01 10:10:00', image_path)

